<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use backend\models\User;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\models\Goods */

$this->title = $model->goodsname;
$this->params['breadcrumbs'][] = ['label' => '商品列表', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;



$com=$model->upfee<=>0 ;
if($com>0){
    $model->upfee='+'.$model->upfee.'%';
}elseif($com==0){
    $model->upfee='0%';
}else{
    $model->upfee=$model->upfee.'%';
}


?>
<style>#readcheck td{width:25%;}</style>
<div class="goods-view">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php if($model->check==3 || $model->check==4){?>
        <p>
            <?= Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>

        </p>
    <?php }?>
    <?php if(!empty(Yii::$app->session['send_info'])){?>
        <p>
            <?=Yii::$app->session['send_info']; ?>
        </p>
        <?php
        unset(Yii::$app->session['send_info']);
    }?>
    <?php $form = ActiveForm::begin(['method'=>'get','action'=>'/goods/check','id'=>'readcheck']); ?>
    <?=Html::hiddenInput('id',$model->id);?>
    <?= DetailView::widget([
        'model' => $model,
        'template'=>function($att, $index){
//        return var_dump($att);
            if($att['attribute']=='remark'){
                return "<tr><th>".$att['label']."</th><td colspan='3'>".$att['value']."</td></tr>";
            }
            if($att['attribute']=='check'){
                return "<tr><th>".$att['label']."</th><td colspan='3'>".$att['value']."</td></tr>";
            }
            if($index % 2 == 0){

                return "<tr><th>".$att['label']."</th><td>".$att['value']."</td>";
            }else{

                return "<th>".$att['label']."</th><td>".$att['value']."</td></tr>";
            }
        },
        'attributes' => [

            'goodsname',
            ['attribute'=>'gys','value'=>function($model){
                $gys=User::findOne($model->gys);
                return !empty($gys) ? $gys->realname : '未分配';
            }],


            'inprice',

            'upfee',

            ['label'=>'商品审核','attribute'=>'check','format'=>'raw','value'=>function(){
                $content=Html::tag("div",Html::radio("ischeck",1,['label'=>'审核通过','value'=>1]),['style'=>'width:33%;float:left']);

                $content.= Html::tag("div",Html::radio("ischeck",0,['label'=>'审核不通过','value'=>0]),['style'=>'width:33%;float:left']);

                return $content;
            }],
            ['label'=>'备注','attribute'=>'remark','format'=>'raw','value'=>function(){
                return Html::textarea('reason','',['rows'=>3,'class'=>'form-control']);
            }]

        ],
    ]) ?>
    <div class="form-group">
        <?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
        <?= Html::Button('关闭', ['class' => 'btn btn-default','id'=>'close']) ?>
    </div>
    <?php ActiveForm::end(); ?>
</div>
<script>
    $("#close").click(function(){
        $('#checkgoods').modal('hide');
        $("#checkgoods").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
        });
    });
</script>